﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TekaMUD.Engine.Blocks;
using TekaMUD.Engine.Framework;

namespace TekaMUD.Engine
{
	public class IaEngine
	{
		/// <summary>
		/// Updates a single NPC
		/// </summary>
		public static void Update(NPC npc)
		{
			// Checks if the agent is ready to be updated.
			if (npc.UpdateTickCounter > 0)
			{
				npc.UpdateTickCounter--;
				return;
			}
			else
			{
				npc.UpdateTickCounter = npc.UpdateFrequencyTicks;
			}

			npc.PreUpdating();

			// Obtain current attitude.
			AgentAttitude aa = npc.Attitude;

			switch (aa)
			{
				case AgentAttitude.Wander:
					PerformWander(npc);
					break;
			}
		}

		private static void PerformWander(NPC npc)
		{
			
			RoomConnection rc = npc.CurrentRoom.GetRandomConnection(true);

			if (rc == null)
			{
				Logger.LogDebug("No exits for NPC " + npc.ToString());
				return;
			}

			NpcMover.GenericMovement(npc, rc);
		}
	}
}
